﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class RoleList : GH.Web.BasePage.PageBase
{

    #region 画面初始化

    protected void Page_Load(object sender, EventArgs e)
    {
        SetGridShow();
        if (Request["RoleID"] != null)
        {
            string strRoleID = Request["RoleID"].ToString().Trim();
            SetRoleValue(strRoleID);
        }
    }


    #endregion

    #region 画面方法


    /// <summary>
    /// 获取角色信息
    /// </summary>
    /// <returns></returns>
    private void SetGridShow()
    {
        GH.BLL.Rights bllRights = new GH.BLL.Rights();
        this.rptList.DataSource = bllRights.GetRoleList();
        this.rptList.DataBind();
    }


    private string GetChecked(string strRole, string strRight)
    {
        GH.BLL.Rights bllRights = new GH.BLL.Rights();
        DataTable dtQuery = bllRights.GetRoleListForId(strRole);
        for (int intRows = 0; intRows < dtQuery.Rows.Count; intRows++)
        {
            if (strRight == dtQuery.Rows[intRows]["权限ID"].ToString())
            {
                return " checked='checked'";
            }
        }
        return "";
    }


    public void SetRoleValue(string strRole)
    {
        GH.BLL.Rights bllRights = new GH.BLL.Rights();
        DataSet dsQuery = bllRights.GetRightSetList();
        string strHtml = "<table style='width: 100%; background-color: Silver;' cellpadding='1px' cellspacing='1px'>";
        strHtml += "<tr><th style='height: 18px; background-color: #B2DBF7; width:10%;'>";
        strHtml += "选择</th><th style='height: 18px; background-color: #B2DBF7;width:90%;'>权限名称</th></tr></table>";
        strHtml += " <table><tr><td style='height: 2px'></td></tr></table>";
        for (int intTables = 0; intTables < dsQuery.Tables.Count; intTables++)
        {
            switch (intTables)
            {
                case 0:
                    strHtml += "<table style='width: 100%; background-color: Silver;' cellpadding='1px' cellspacing='1px'>";
                    strHtml += "<tr><th style='height: 18px; background-color: #B2DBF7; text-align:left'>系统维护</th></tr></table>";
                    break;
                case 1:
                    strHtml += "<table style='width: 100%; background-color: Silver;' cellpadding='1px' cellspacing='1px'>";
                    strHtml += "<tr><th style='height: 18px; background-color: #B2DBF7; text-align:left'>会员管理</th></tr></table>";
                    break;
                case 2:
                    strHtml += "<table style='width: 100%; background-color: Silver;' cellpadding='1px' cellspacing='1px'>";
                    strHtml += "<tr><th style='height: 18px; background-color: #B2DBF7; text-align:left'>工会管理</th></tr></table>";
                    break;
                case 3:
                    strHtml += "<table style='width: 100%; background-color: Silver;' cellpadding='1px' cellspacing='1px'>";
                    strHtml += "<tr><th style='height: 18px; background-color: #B2DBF7; text-align:left'>职工福利</th></tr></table>";
                    break;
                default:
                    break;
            }
            strHtml += "<table style='width: 100%; background-color: Silver' cellpadding='1px' cellspacing='1px'>";
            for (int intRows = 0; intRows < dsQuery.Tables[intTables].Rows.Count; intRows++)
            {
                strHtml += "<tr><td style='height: 18px; background-color: #FFFFFF;width:10%; padding-left:10px;'>";
                strHtml += "<input value='" + dsQuery.Tables[intTables].Rows[intRows]["权限ID"].ToString() + "'" + GetChecked(strRole.Trim(), dsQuery.Tables[intTables].Rows[intRows]["权限ID"].ToString());
                strHtml += " name='PopList' type='checkbox' /></td>";
                strHtml += "<td style='height: 18px; background-color: #FFFFFF; width:90%;'>";
                strHtml += dsQuery.Tables[intTables].Rows[intRows]["权限名称"].ToString();
                strHtml += "</td></tr>";
            }
            strHtml += "</table>";
        }

        Response.Write(strHtml);
        Response.End();
    }


    public List<GH.Model.用户信息> Get用户信息List()
    {
        GH.BLL.User bllUser = new GH.BLL.User();
        return bllUser.DataTableToList(bllUser.GetAllList().Tables[0]);
    }

    public void SetUserGroupValue(string strRole)
    {

    }


    #endregion

}

